<template>
  <el-card class="page-tools" shadow="hover">
    <el-row type="flex" justify="space-between" align="middle">
      <el-col>
        <div v-if="showBefore" class="before">
          <i class="el-icon-info" />
          <!-- 定义前面得插槽 -->
          <slot name="before" />
        </div>
        <div v-else class="input">
          <!-- <i class="el-icon-info" /> -->
          <el-input
            v-for="item in inputArr"
            :key="item"
            v-model="key[dict[item]]"
            style="margin-right:10px;"
            size="mini"
            :placeholder="item"
            clearable
          />
          <el-button
            size="mini"
            type="primary"
            @click="$emit('search', key)"
          >查询</el-button>
        </div>
      </el-col>
      <el-col>
        <el-row type="flex" justify="end">
          <!-- 定义后面的插槽 -->
          <slot name="after" />
          <el-button type="success" @click="$emit('add')">{{ add }}</el-button>
        </el-row>
      </el-col>
    </el-row>
  </el-card>
</template>

<script>
export default {
  props: {
    showBefore: {
      type: Boolean,
      default: false
    },
    add: {
      default: '新增',
      type: String
    },
    dict: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      key: {
        user_id: '',
        user_tel: '',
        create_time: ''
      }
    }
  },
  computed: {
    inputArr() {
      return Object.keys(this.dict)
    }
  }
}
</script>

<style lang="scss">
.page-tools {
  margin: 10px 0;
  .before {
    line-height: 34px;
    i {
      margin-right: 5px;
      color: #409eff;
    }
    display: inline-block;
    padding: 0px 10px;
    border-radius: 3px;
    border: 1px solid rgba(145, 213, 255, 1);
    background: rgba(230, 247, 255, 1);
  }
}
.input {
  display: flex;
}
</style>
